package com.itheima.service.impl;

import com.itheima.common.utils.DateUtils;
import com.itheima.mapper.MemberMapper;
import com.itheima.mapper.OrderMapper;
import com.itheima.mapper.SetmealMapper;
import com.itheima.service.MemberService;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private SetmealMapper setmealMapper;


    /**
     * 运营数据统计
     * @return
     */
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String, Object> map = new HashMap<>();

        //当天日期
        Date reportDate = DateUtils.getToday();
        String today = DateUtils.parseDate2String(reportDate);
        //获取本周一的日期
        Date thisWeekMonday = DateUtils.getThisWeekMonday();
        String Monday = DateUtils.parseDate2String(thisWeekMonday);
        //获取本月第一天
        Date firstDay4ThisMonth = DateUtils.getFirstDay4ThisMonth();
        String month = DateUtils.parseDate2String(firstDay4ThisMonth);

        //报表日期
        map.put("reportDate", today);
        //今日新增会员数
        Integer todayNewMember = memberMapper.newMemberCountByDate(today);
        map.put("todayNewMember", todayNewMember);
        //总会员数
        Integer totalMember = memberMapper.newMemberTotalCount();
        map.put("totalMember", totalMember);
        //本周新增会员数
        Integer thisWeekNewMember = memberMapper.newMemberCountByWeek(Monday);
        map.put("thisWeekNewMember", thisWeekNewMember);
        //本月新增会员数
        Integer thisMonthNewMember = memberMapper.newMemberCountByMonth(month);
        map.put("thisMonthNewMember", thisMonthNewMember);
        //今日预约数
        Integer todayOrderNumber = orderMapper.orderCountByDate(today);
        map.put("todayOrderNumber", todayOrderNumber);
        //本周预约数
        Integer thisWeekOrderNumber = orderMapper.orderCountByWeek(Monday);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);
        //本月预约数
        Integer thisMonthOrderNumber = orderMapper.orderCountByMonth(month);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
        //今日到诊数
        Integer todayVisitsNumber = orderMapper.visitCountByDate(today);
        map.put("todayVisitsNumber", todayVisitsNumber);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderMapper.visitMemberCountByWeek(Monday);
        map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderMapper.visitMemberCountByMonth(month);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);

        //热门套餐查询
        List<Map> hotSetmeal = orderMapper.gethotSetmeal();
        map.put("hotSetmeal", hotSetmeal);
        return map;
    }
}
